home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / BEND.ZIP / BEND.INC next >
Encoding:
Text File  |  1997-06-13  |  4.6 KB  |  100 lines

  1. // ********************************************************
  2. // OBJECT BENDER INCLUDE FILE FOR PERSISTENCE OF VISION 3.x
  3. // ********************************************************
  4. //
  5. // Created by Chris Colefax, 13 June 1997
  6. //
  7. // See "Bend.txt" for more information.
  8. //
  9. // ********************************************************
  10.  
  11. // CHECK BEND OBJECT AND REQUIRED PARAMETERS
  12. // *****************************************
  13.    #declare _BN_tempver = version #version 3.0
  14.    #declare _BN_nobend = false
  15.    #ifndef (bend_object)  #declare _BN_nobend = true #declare _BN_warning = "You must specify a bend_object!" #end
  16.    #ifndef (object_axis1) #declare _BN_axis1  = -y   #else #declare _BN_axis1 = object_axis1 * <1, 1, 1> #end
  17.    #ifndef (object_axis2) #declare _BN_axis2  =  y   #else #declare _BN_axis2 = object_axis2 * <1, 1, 1> #end
  18.    #ifndef (bend_angle)   #declare _BN_angle  = 45   #else #declare _BN_angle = bend_angle               #end
  19.  
  20.    #declare _BN_axisvec = _BN_axis2 - _BN_axis1
  21.    #if (_BN_axisvec.x = 0 & _BN_axisvec.y = 0 & _BN_axisvec.z = 0) #declare _BN_nobend = true #declare _BN_warning = "object_axis1 and object_axis2 must be different!" #end
  22.  
  23.    #if (_BN_nobend) #warning concat (_BN_warning, "\n") #else
  24.  
  25. // DETERMINE BEND DIRECTION
  26. // ************************
  27.    #ifndef (bend_direction) #declare _BN_dir = x #else #declare _BN_dir = vnormalize(bend_direction * <1, 1, 1>) #end
  28.    #declare _BN_roty = degrees(atan2(_BN_axisvec.x, _BN_axisvec.z))
  29.    #declare _BN_rotx = degrees(atan2(vlength (_BN_axisvec * <1, 0, 1>), _BN_axisvec.y))
  30.    #declare _BN_dir = vrotate(vrotate(_BN_dir, -y * _BN_roty), -x * _BN_rotx)
  31.  
  32. // DON'T BEND OBJECT IF ANGLE IS 0
  33. // *******************************
  34.    #if (_BN_angle = 0 | abs(_BN_dir.y) = 1) object {bend_object} #else
  35.  
  36. // DETERMINE OTHER PARAMETERS
  37. // **************************
  38.    #declare _BN_ospin = degrees(atan2(_BN_dir.x, _BN_dir.z))
  39.    #if (_BN_angle < 0) #declare _BN_angle = abs(_BN_angle) #declare _BN_ospin = _BN_ospin + 180 #end
  40.    #if (_BN_angle > 360) #warning "bend_angle cannot be larger than 360 degrees!\n" #declare _BN_angle = 360 #end
  41.    #ifndef (bend_smoothness) #declare _BN_step = int(_BN_angle / 3.6) #else #declare _BN_step = int(bend_smoothness * _BN_angle / 360) #end
  42.    #if (_BN_step < 6) #declare _BN_step = 1 / 6 #else #declare _BN_step = 1 / _BN_step #end
  43.    #ifndef (bend_start) #declare bend_start = 0 #end
  44.    #if (bend_start < 0 | bend_start >= 1)
  45.       #warning "bend_start must be bewteen 0 and 1!\n"
  46.       #declare bend_start = 0 #end
  47.    #ifndef (bend_finish) #declare bend_finish = 1 #end
  48.    #if (bend_finish > 1 | bend_finish <= bend_start)
  49.       #warning "bend_finish must be larger than bend_start, but less than 1!\n"
  50.       #declare bend_finish = 1 #end
  51.    #declare _BN_obase      = _BN_axis1 + y * vlength(_BN_axisvec) * bend_start
  52.    #declare _BN_oheight    = vlength(_BN_axisvec) * (bend_finish - bend_start)
  53.    #declare _BN_clipheight = _BN_oheight * _BN_step / 2
  54.    #declare _BN_clipangle  = _BN_angle * _BN_step / 2
  55.    #declare _BN_radius     = (_BN_oheight * 180) / (pi * _BN_angle)
  56.  
  57. // CREATE BENT OBJECT
  58. // ******************
  59.    union {
  60.  
  61. // FIRST SECTION (STRAIGHT)
  62. // ************************
  63.    object {bend_object
  64.       translate -_BN_obase
  65.       rotate -y * _BN_roty rotate -x * _BN_rotx rotate -y * _BN_ospin
  66.       clipped_by {plane {y, 0 rotate x * _BN_clipangle translate y * _BN_clipheight}}
  67.          translate -z * _BN_radius}
  68.  
  69. // MIDDLE SECTION (BENT)
  70. // *********************
  71.    #declare _BN_count = _BN_step #while (_BN_count < 1)
  72.       object {bend_object
  73.          translate -_BN_obase
  74.          rotate -y * _BN_roty rotate -x * _BN_rotx rotate -y * _BN_ospin
  75.          translate -(y * _BN_count * _BN_oheight)
  76.          clipped_by {intersection {
  77.             plane {-y, 0 rotate -x * _BN_clipangle translate -y * _BN_clipheight}
  78.             plane { y, 0 rotate  x * _BN_clipangle translate  y * _BN_clipheight}}}
  79.          translate -z * _BN_radius rotate x * _BN_count * _BN_angle}
  80.    #declare _BN_count = _BN_count + _BN_step #end
  81.  
  82. // LAST SECTION (STRAIGHT)
  83. // ***********************
  84.    object {bend_object
  85.       translate -_BN_obase
  86.       rotate -y * _BN_roty rotate -x * _BN_rotx rotate -y * _BN_ospin
  87.       translate -(y * _BN_oheight)
  88.       clipped_by {plane {-y, 0 rotate -x * _BN_clipangle translate -y * _BN_clipheight}}
  89.       translate -z * _BN_radius rotate x * _BN_angle}
  90.  
  91. // POSITION OBJECT
  92. // ***************
  93.    translate z * _BN_radius
  94.    rotate y * _BN_ospin rotate x * _BN_rotx rotate y * _BN_roty
  95.    translate _BN_obase
  96.    }
  97.  
  98.    #end #end
  99.    #version _BN_tempver
  100.